import { messages } from "share/common";
import React, { Component } from "react";
import { connect } from "react-redux";
import "styles/supplier-management/overview/consumer-other-setting.scss";
import Importer from "components/template/importer/index";
import config from "config";

class RankSync extends Component {
  constructor(props) {
    super(props);
    this.state = {
      flieUploading: false, //文件是否正在上传
    };
    //导入结果展示
    this.resultDisplay = ({ code, msg, failRegulationIds, successCount }) => {
      return (
        <span className="didi-regulation-importer-result">
          <span className="display-block result-content">
            {messages("supplier-1.key25") /*导入结果：*/}
            {msg}
          </span>
          {typeof successCount === "number" && (
            <span className="display-block success">
              {messages("supplier-1.key26") /*导入成功*/}
              {successCount}条
            </span>
          )}
          {failRegulationIds instanceof Array && (
            <span className="display-block fail">
              {messages("supplier-1.key27") /*导入失败*/}
              {failRegulationIds.length}条
            </span>
          )}
          {failRegulationIds && failRegulationIds instanceof Array && failRegulationIds.length > 0 && (
            <span className="result-block">
              {messages("supplier-1.key28") /*失败制度ID:*/}
              <br />
              {failRegulationIds.join(" , ")}
            </span>
          )}
        </span>
      );
    };
  }

  resultTemplate = (data) => {
    console.log(data);
    const Result = this.resultDisplay;
    return <Result {...data} />;
  };

  render() {
    const templates = [
      {
        downloadName: messages("supplier-1.key882") /*职级导入模板*/,
        templateName: messages("supplier-1.key882") /*职级导入模板*/,
        downloadUrl: "/vendor-info-service/api/vendor/fanjia/grades/template/get",
        downloading: "loading",
      },
    ];

    return (
      <li key="async">
        {" "}
        {messages("supplier-1.key67") /*点击*/}&nbsp;
        <Importer
          triggerNode={<a>{messages("supplier-1.key883") /*同步职级*/}</a>}
          templateOptions={{
            templateList: templates,
            errorParser: (err) => err.message,
          }}
          uploadOptions={{
            uploadUrl: `${config.baseUrl}/vendor-info-service/api/vendor/fanjia/grades/push`,
            parseUploadResult: (value) => value,
          }}
          parseUploadResult={this.resultTemplate}
        />
        &nbsp;{" "}
        {
          messages(
            "supplier-1.key884"
          ) /*先同步泛嘉职级信息，目前仅支持新增职级信息，如需修改/删除职级信息，请联系泛嘉处理*/
        }
      </li>
    );
  }
}

function mapStateToProps(state) {
  return {};
}

export default connect(mapStateToProps)(RankSync);
